home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / FLOATING / PROCEDUR / SOURCE_C / MAIN.C < prev   
C/C++ Source or Header  |  1991-07-09  |  4KB  |  224 lines

  1. /********************************************************************
  2.     FLOATING WINDOWS 1.0
  3.     Copyright 1990 Patrick Doane. All Rights Reserved
  4.  ********************************************************************/
  5.  
  6. #include "Floating.h"
  7. #include "main.h"
  8.  
  9. #define    TypeMask            0xFF000000
  10. #define    SuspendResumeEvt    0x01000000
  11. #define SuspendResumeBit    0x00000001
  12.  
  13. WindowPtr    windowA,windowB,windowC;
  14. WindowPtr    floatWindow,floatWindow2;
  15. Boolean        running;
  16. Boolean        WNEImplemented;
  17. Boolean        inBackground;
  18.  
  19. void main(void)
  20. {
  21.     Initialize();
  22.     MakeWindows();
  23.     
  24.     EventLoop();
  25. }
  26.  
  27. void    Initialize(void)
  28. {
  29.     InitGraf(&thePort);
  30.     InitFonts();
  31.     InitWindows();
  32.     InitCursor();
  33.     
  34.     WNEImplemented = (NGetTrapAddress(0x60,ToolTrap) !=
  35.         NGetTrapAddress(0x9F,ToolTrap));
  36.     
  37.     inBackground = false;
  38.     
  39.     running = true;
  40.     
  41.     InitFloat();
  42. }
  43.  
  44. void    MakeWindows(void)
  45. {
  46.     floatWindow = NewFloatingWindow(131,0L);
  47.     
  48.     windowA = GetNewWindow(128,0L,0L);
  49.     SelectTheWindow(windowA);
  50.     windowB = GetNewWindow(129,0L,0L);
  51.     SelectTheWindow(windowB);
  52.     floatWindow2 = NewFloatingWindow(132,0L);
  53.     windowC = GetNewWindow(130,0L,0L);
  54.     SelectTheWindow(windowC);
  55. }
  56.  
  57. void    EventLoop(void)
  58. {
  59.     EventRecord    theEvent;
  60.     
  61.     do
  62.     {    if (WNEImplemented)
  63.         {    WaitNextEvent(everyEvent,&theEvent,0,0L);
  64.             DoEvent(&theEvent);
  65.         }
  66.         else
  67.         {    SystemTask();
  68.             if (GetNextEvent(everyEvent,&theEvent))
  69.                 DoEvent(&theEvent);
  70.         }
  71.     }
  72.     while (running);
  73. }
  74.  
  75. void    DoEvent(EventRecord *theEvent)
  76. {
  77.     switch(theEvent->what)
  78.     {    case nullEvent:
  79.             break;
  80.         case mouseDown:
  81.             DoMouseDown(theEvent);
  82.             break;
  83.         case activateEvt:
  84.             if (theEvent->modifiers & activeFlag)
  85.                 DoActivate(theEvent);
  86.             else
  87.                 DoDeactivate(theEvent);
  88.         case updateEvt:
  89.             DoUpdate(theEvent);
  90.             break;
  91.         case app4Evt:
  92.             switch (theEvent->message & TypeMask)
  93.             {    case SuspendResumeEvt:
  94.                     if (theEvent->message & SuspendResumeBit)
  95.                         DoResume(theEvent);
  96.                     else
  97.                         DoSuspend(theEvent);
  98.                     break;
  99.             }
  100.             break;
  101.     }
  102. }
  103.  
  104. void    DoMouseDown(EventRecord *theEvent)
  105. {
  106.     WindowPtr    whichWindow;
  107.     short        thePart;
  108.     
  109.     thePart = FindWindow(theEvent->where,&whichWindow);
  110.     
  111.     switch(thePart)
  112.     {    case inDesk:
  113.             break;
  114.         case inMenuBar:
  115.             DoMenu(theEvent);
  116.             HiliteMenu(0);
  117.             break;
  118.         case inSysWindow:
  119.             SystemClick(theEvent,whichWindow);
  120.             break;
  121.         case inContent:
  122.             SelectTheWindow(whichWindow);
  123.             break;
  124.         case inDrag:
  125.             DragTheWindow(whichWindow,theEvent);
  126.             break;
  127.         case inGrow:
  128.             GrowTheWindow(whichWindow,theEvent->where);
  129.             break;
  130.         case inGoAway:
  131.             if (TrackGoAway(whichWindow,theEvent->where))
  132.                 CloseTheWindow(whichWindow);
  133.             if (!FrontWindow())
  134.                 running = false;
  135.             break;
  136.         case inZoomIn:
  137.         case inZoomOut:
  138.             ZoomTheWindow(whichWindow,theEvent->where,thePart);
  139.             break;
  140.     }
  141. }
  142.  
  143. void    DoMenu(EventRecord *theEvent)
  144. {
  145. }
  146.  
  147. void    GrowTheWindow(WindowPtr whichWindow,Point where)
  148. {
  149.     long    newBounds;
  150.     Rect    growRect;
  151.     
  152.     growRect = (**GetGrayRgn()).rgnBBox;
  153.     growRect.left = 64;
  154.     growRect.top = 64;
  155.     
  156.     newBounds = GrowWindow(whichWindow,where,&growRect);
  157.     if (newBounds)
  158.     {    EraseRect(&whichWindow->portRect);
  159.         SizeWindow(whichWindow,LoWord(newBounds),HiWord(newBounds),true);
  160.         EraseRect(&whichWindow->portRect);
  161.         InvalRect(&whichWindow->portRect);
  162.     }
  163. }
  164.  
  165. void    ZoomTheWindow(WindowPtr whichWindow,Point where,short inOrOut)
  166. {
  167.     Rect        portRect;
  168.     
  169.     if (TrackBox(whichWindow,where,inOrOut))
  170.     {    portRect = whichWindow->portRect;
  171.         
  172.         EraseRect(&portRect);
  173.         ZoomWindow(whichWindow,inOrOut,false);
  174.         portRect = whichWindow->portRect;
  175.         InvalRect(&portRect);
  176.     }
  177. }
  178.  
  179. void    DoActivate(EventRecord *theEvent)
  180. {
  181.     WindowPtr    whichWindow;
  182.     
  183.     whichWindow = (WindowPtr)theEvent->message;
  184.     SetPort(whichWindow);
  185.     DrawGrowIcon(whichWindow);
  186. }
  187.  
  188. void    DoDeactivate(EventRecord *theEvent)
  189. {
  190.     WindowPtr    whichWindow;
  191.     
  192.     whichWindow = (WindowPtr)theEvent->message;
  193.     DrawGrowIcon(whichWindow);
  194. }
  195.  
  196. void    DoUpdate(EventRecord *theEvent)
  197. {
  198.     WindowPtr    whichWindow;
  199.     GrafPtr        savePort;
  200.     
  201.     whichWindow = (WindowPtr)theEvent->message;
  202.     
  203.     GetPort(&savePort);
  204.     BeginUpdate(whichWindow);
  205.     DrawGrowIcon(whichWindow);
  206.     EndUpdate(whichWindow);
  207.     SetPort(savePort);
  208. }
  209.  
  210. void    DoResume(EventRecord *theEvent)
  211. {
  212.     register WindowPtr    theWindow;
  213.     
  214.     inBackground = false;
  215.     ShowFloats();
  216. }
  217.  
  218. void    DoSuspend(EventRecord *theEvent)
  219. {
  220.     register WindowPtr    theWindow;
  221.     
  222.     inBackground = true;
  223.     HideFloats();
  224. }